package com.lr.generatorplus.utils;

import java.io.Serializable;

public class Result<T> implements Serializable {

    private static final long serialVersionUID = 0L;

    public static final int SUCCESS_CODE = 0;
    public static final String SUCCESS_MSG = "成功";


    protected int code;


    protected String msg;

    protected T data;

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> success(T data) {
        return new Result(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static <T> Result<T> fail(int code, String msg) {
        return fail(null, code, msg);
    }

    public static <T> Result<T> fail(T data, int code, String msg) {
        return new Result(code, msg, data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}